package songgao.papers.iEC;

import java.util.ArrayList;
import java.util.HashSet;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Master {

	public static Master generateMaster() {
		Master master = new Master();
		master.slaves = new HashSet<Slave>();
		master.populationPool = new ArrayList<Population>();
		for (int i = 0; i < DataManager.INSTANCE.getParameters().getPopulationPoolSize(); i++)
			master.populationPool.add(Population.generatePopulation());
		return master;
	}
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String encodedKey;

	@Persistent(defaultFetchGroup = "true", mappedBy = "master")
	private HashSet<Slave> slaves;

	@Persistent(defaultFetchGroup = "true")
	private ArrayList<Population> populationPool;


	/**
	 * @param encodedKey
	 *            the encodedKey to set
	 */
	public void setEncodedKey(String encodedKey) {
		this.encodedKey = encodedKey;
	}

	/**
	 * @return the encodedKey
	 */
	public String getEncodedKey() {
		return encodedKey;
	}

	/**
	 * @param slaves
	 *            the slaves to set
	 */
	public void setSlaves(HashSet<Slave> slaves) {
		this.slaves = slaves;
	}

	/**
	 * @return the slaves
	 */
	public HashSet<Slave> getSlaves() {
		return slaves;
	}

	/**
	 * @param populationPool
	 *            the populationPool to set
	 */
	public void setPopulationPool(ArrayList<Population> populationPool) {
		this.populationPool = populationPool;
	}

	/**
	 * @return the populationPool
	 */
	public ArrayList<Population> getPopulationPool() {
		return populationPool;
	}

}
